package KY;

import java.util.Scanner;

class TreeNode{
    char val;
    TreeNode right;
    TreeNode left;
    public TreeNode(){}
    public TreeNode(char val){
        this.val = val;
    }
}
public class KY11 {
    public static int index;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while ((scanner.hasNext())){
            String str = scanner.nextLine();
            //根据先序遍历还原二叉树
            TreeNode root = preOrderBuild(str);
            //根据中序遍历输出二叉树
            inOrder(root);
            System.out.println();
            index = 0;
        }
    }
    public static void inOrder(TreeNode root){
        if(root == null){
            return;
        }
        inOrder(root.left);
        System.out.println(root.val + "");
        inOrder(root.right);
    }

    public static TreeNode preOrderBuild(String str){
        char ch = str.charAt(index);
        if(ch == '#'){
            return null;
        }
        TreeNode root = new TreeNode(ch);
        index++;
        root.left = preOrderBuild(str);
        index++;
        root.right = preOrderBuild(str);
        return root;
    }
}
